﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IP_PROJECT
{
    public partial class Image1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string id = Request.QueryString["Id"];
            if (id != null)
            {
                DataClassesDataContext db = new DataClassesDataContext();
                var result = from u in db.Images
                            where u.Id == Int32.Parse(id)
                            select u;
                List<Image> images = result.ToList();
                Response.ContentType = "application/octet-stream";
                if (images.Count > 0)
                {
                    Response.AddHeader("content-disposition", "attachment;filename=" + images[0].Name);
                    Response.BinaryWrite(images[0].Content.ToArray());
                    Response.Flush();
                    Response.End();
                }
            }
        }
    }
}